#pragma once

namespace Tmpl {

class Entity;
class EntityDoodadd
{
public:
	enum DoodaddCondition
	{
		DOODADD_CONDITION_ALIVE			= 1 << 0,
		DOODADD_CONDITION_DEAD			= 1 << 1,
	};

	void Kill();

	Entity* GetOwner(){return mOwner;}
	Vec2f GetPos() const { return mPos; }
	float GetSize() const { return mSize; }

	// HP
	float GetHP() const {return mHP;}
	float GetHPMax() const {return mHPMax;}
	float GetHPPercent() const { return(mHPMax<=0.0f) ? 100.0f : Max(0.0f,Min(100.0f,mHP * 100.0f / mHPMax));}
	void AddHP(float hp, int entitySource);

	// Condition
	void ConditionSetFlags(int flag){mConditionFlags = flag; }
	void ConditionAddFlag(int flag){mConditionFlags |= flag; }
	void ConditionRemoveFlag(int flag){mConditionFlags &= ~flag; }
	bool ConditionHasFlag(int flag) const {return ((mConditionFlags & flag) == flag);}
	int ConditionGetFlags() const {return mConditionFlags; }

private:
	friend class EntityDoodaddSystem;

	Entity* mOwner;
	Vec2f mPos;
	float mSize;

	int mConditionFlags;
	float mHP, mHPMax;
};

struct UnitData;
class EntityDoodaddSystem
{
public:
	static void Init();
	static void Clear();

	static int NewDoodadd(Entity* owner, Vec2f pos, const UnitData& data);
	static void RemoveDoodadd(int id);
	static EntityDoodadd* GetDoodadd(int id);

	static JobHandle Update(JobHandle dependency);

private:
	static void UpdateDoodaddChunk(int chunk);
};

} // namespace Tmpl